﻿package com.hongguan.oms.service.grid;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.hongguan.oms.domain.grid.GridAuthInfo;
import com.hongguan.oms.domain.grid.GridAuthInfoExample;
import com.hongguan.oms.service.BaseExampleService;

/**
 * GridAuthorityInfo Service
 * 
 * @author
 * @param <E>
 * 
 */
@Service
public class GridAuthInfoService extends
		BaseExampleService<GridAuthInfo, GridAuthInfoExample> {
	public GridAuthInfoService() {
		namespace = "GRID_AUTH_INFO";
	}

	public List gridAuthSelect(Map param, int start, int end) {
		return (List) getSqlMapClientTemplate().queryForList(
				"GRID_AUTH_INFO.auth_select", param, start, end);
	}

	public List gridAuthSelectAll() {
		return (List) getSqlMapClientTemplate().queryForList(
				"GRID_AUTH_INFO.auth_select");
	}

	public int gridAuthCount(Map param) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"GRID_AUTH_INFO.auth_count", param);
	}

	public void gridAuthAdd(Map param) {
		getSqlMapClientTemplate().insert("GRID_AUTH_INFO.auth_add", param);
	}

	public void gridAuthEdit(Map param) {
		getSqlMapClientTemplate().update("GRID_AUTH_INFO.auth_edit", param);
	}

	public void gridAuthDel(Map param) {
		getSqlMapClientTemplate().delete("GRID_AUTH_INFO.auth_del", param);
	}

	public List<GridAuthInfo> authQueryByRoleId(Map param) {
		return getSqlMapClientTemplate().queryForList(
				"GRID_AUTH_INFO.auth_querybyroleid", param);
	}

	public GridAuthInfo queryGridAuthInfoByRoleId(String roleId) {
		GridAuthInfo result = null;
		Map param = new HashMap();
		param.put("role_id", roleId);
		List<GridAuthInfo> list = authQueryByRoleId(param);
		if (!list.isEmpty()) {
			result = list.get(0);
			List<Long> entityIds = new ArrayList<Long>();
			for (GridAuthInfo gridAuthInfo : list) {
				entityIds.add(gridAuthInfo.getEntityId());
			}
			result.setEntityIds(entityIds);
		}
		return result;
	}
}
